package com.csu.petstore.controller;

import com.csu.petstore.common.CommonResponse;
import com.csu.petstore.log.Syslog;
import com.csu.petstore.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/ajax")
@Validated
public class AjaxController {
    @Autowired
    private UserService userService;

    @GetMapping("/users")
    @Syslog(modelName = "检查用户名",methodDesc = "后台请求检查用户名")
    public CommonResponse<String> checkUserName(@RequestParam("username") String username){
        System.out.println(11111);
        boolean isExistUser = userService.isExistUser(username);
        String msg = "";
        if (isExistUser)
            msg = "exist";
        else
            msg = "no exist";
        return CommonResponse.createForSuccess(msg);
    }
}
